package cn.wolfcode.qo;

import lombok.Data;

import java.util.List;

/**
 * ClassName PageResult
 * Create by Mike
 * Date 2021/8/1 16:36
 */
@Data
public class PageResult<T> {

    private int currentPage;
    private int pageSize;
    private int totalCount;
    private List<T> data;
    private int totalPage;
    private int prevPage;
    private int nextPage;

    public PageResult(int currentPage,int pageSize,int totalCount,List<T> data){
        this.currentPage = currentPage;
        this.pageSize = pageSize;
        this.totalCount = totalCount;
        this.data = data;

        if (totalCount == 0){
            this.currentPage = 0;
            this.totalPage = 0;
            return;
        }

        this.totalPage = totalCount % pageSize == 0 ? totalCount / pageSize : totalCount / pageSize + 1;

        this.prevPage = Math.max(currentPage - 1, 1);

        this.nextPage = Math.min(currentPage + 1, totalPage);

    }

}
